package com.jlz.actions.console.category;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Standard;
import org.springframework.beans.factory.annotation.Autowired;

import com.jlz.beans.core.CategoryBean;
import com.jlz.beans.core.CategoryTable;
import com.jlz.beans.def.ColumnBean;
import com.jlz.managers.def.Columns;

@Standard(rest={"columnId", "action"})
public class ColumnsAction {
	Long columnId = null;
	String action = null;
	@Autowired Columns columns;
	ColumnBean column = null;
	CategoryBean category = null;
	
	public String execute(){
		if(columnId == null) return "list";
		column = columns.get(columnId);
		if(column == null)return "list";
		category = column.getCategory();
		//
		if(StringUtils.isBlank(action))return "edit";
		CategoryTable table = category.getTableOf(column.getType());
		switch(action.charAt(0)){
			case 'u':table.reorderColumn(column, -1);break;
			case 'd':table.reorderColumn(column, +1);break;
			case 'r':table.removeColumn(column);break;
		}
		return "edit";
	}
	
	public Long getColumnId() {
		return columnId;
	}

	public void setColumnId(Long columnId) {
		this.columnId = columnId;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public ColumnBean getColumn() {
		return column;
	}

	public void setColumn(ColumnBean column) {
		this.column = column;
	}

	public CategoryBean getCategory() {
		return category;
	}

	public void setCategory(CategoryBean category) {
		this.category = category;
	}
	
	

}
